﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.MaintenancePlanVMs
{
    public partial class MaintenancePlanListVM : BasePagedListVM<MaintenancePlan_View, MaintenancePlanSearcher>
    {
        
        protected override IEnumerable<IGridColumn<MaintenancePlan_View>> InitGridHeader()
        {
            return new List<GridColumn<MaintenancePlan_View>>{
                
                this.MakeGridHeader(x => x.MaintenancePlan_PlanName).SetTitle(@Localizer["Page.计划名称"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_Equipment).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_EquipmentName).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_PlanType).SetTitle(@Localizer["Page.计划类型"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_IntervalDays).SetTitle(@Localizer["Page.周期"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_NextDueDate).SetTitle(@Localizer["Page.下次执行日期"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_IsActive).SetTitle(@Localizer["Page.是否启用"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.MaintenancePlan_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<MaintenancePlan_View> GetSearchQuery()
        {
            var query = DC.Set<MaintenancePlan>()
                
                .CheckContain(Searcher.PlanName, x=>x.PlanName)
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckContain(Searcher.EquipmentName, x=>x.EquipmentName)
                .CheckEqual(Searcher.PlanType, x=>x.PlanType)
                .CheckEqual(Searcher.IntervalDays, x=>x.IntervalDays)
                .CheckBetween(Searcher.NextDueDate?.GetStartTime(), Searcher.NextDueDate?.GetEndTime(), x => x.NextDueDate, includeMax: false)
                .CheckEqual(Searcher.IsActive, x=>x.IsActive)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new MaintenancePlan_View
                {
				    ID = x.ID,
                    
                    MaintenancePlan_PlanName = x.PlanName,
                    MaintenancePlan_Equipment = x.Equipment.ID,
                    MaintenancePlan_EquipmentName = x.EquipmentName,
                    MaintenancePlan_PlanType = x.PlanType,
                    MaintenancePlan_IntervalDays = x.IntervalDays,
                    MaintenancePlan_NextDueDate = x.NextDueDate,
                    MaintenancePlan_IsActive = x.IsActive,
                    MaintenancePlan_CreateTime = x.CreateTime,
                    MaintenancePlan_UpdateTime = x.UpdateTime,
                    MaintenancePlan_CreateBy = x.CreateBy,
                    MaintenancePlan_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class MaintenancePlan_View: MaintenancePlan
    {
        
        public string MaintenancePlan_PlanName { get; set; }
        public long? MaintenancePlan_Equipment { get; set; }
        public string MaintenancePlan_EquipmentName { get; set; }
        public MaintenanceTypeEnum? MaintenancePlan_PlanType { get; set; }
        public int? MaintenancePlan_IntervalDays { get; set; }
        public DateTime? MaintenancePlan_NextDueDate { get; set; }
        public bool? MaintenancePlan_IsActive { get; set; }
        public DateTime? MaintenancePlan_CreateTime { get; set; }
        public DateTime? MaintenancePlan_UpdateTime { get; set; }
        public string MaintenancePlan_CreateBy { get; set; }
        public string MaintenancePlan_UpdateBy { get; set; }

    }

}